import Vue from 'vue';
import Router from 'vue-router';
//import router from '@vue/cli-service/generator/router/template/src/router';

Vue.use(Router);


const router = new Router({
    routes: [
        {
            path: '/Home',
            component: () => import(/* webpackChunkName: "home" */ '../components/common/Home.vue'),
            meta: { title: '自述文件' },
            children: [
                {
                    path: '/user',
                    component: () => import(/* webpackChunkName: "icon" */ '../components/page/User'),
                    meta: { title: '用户信息' }
                },
                {
                    path: '/subject',
                    component: () => import(/* webpackChunkName: "icon" */ '../components/page/Subject'),
                    meta: { title: '专业信息' }
                },
                {
                    path: '/college',
                    component: () => import(/* webpackChunkName: "icon" */ '../components/page/College'),
                    meta: { title: '学校信息' }
                },
                {
                    path: '/adjust',
                    component: () => import(/* webpackChunkName: "icon" */ '../components/page/Adjust'),
                    meta: { title: '调剂信息' }
                },
                {
                    path: '/apply',
                    component: () => import(/* webpackChunkName: "icon" */ '../components/page/Apply'),
                    meta: { title: '审核信息' }
                },
                {
                    path: '/news',
                    component: () => import(/* webpackChunkName: "icon" */ '../components/page/News'),
                    meta: { title: '新闻公告' }
                },
                {
                    path: '/404',
                    component: () => import(/* webpackChunkName: "404" */ '../components/page/404.vue'),
                    meta: { title: '404' }
                },
                {
                    path: '/403',
                    component: () => import(/* webpackChunkName: "403" */ '../components/page/403.vue'),
                    meta: { title: '403' }
                }
            ]
        },


        {
            path: '/',
            component: () => import(/* webpackChunkName: "home" */ '../components/page/Content'),
            meta: { title: '自述文件' },
            children: [

                {
                    path: '/index',
                    component: () => import(/* webpackChunkName: "dashboard" */ '../components/page/IndexAdjust'),
                    meta: { title: '首页管理' }
                },
                {
                    path: '/index-news',
                    component: () => import(/* webpackChunkName: "dashboard" */ '../components/page/ViewNews'),
                    meta: { title: '新闻公告' }
                },
                {
                    path: '/contact',
                    component: () => import(/* webpackChunkName: "dashboard" */ '../components/web/Contact'),
                    meta: {title: '个人中心'},
                    children: [
                        {
                            path: 'person',
                            component: () => import(/* webpackChunkName: "dashboard" */ '../components/web/Person'),
                            meta: {title: '个人信息'}
                        },
                        {
                            path: 'my-adjust',
                            component: () => import(/* webpackChunkName: "dashboard" */ '../components/web/MyAdjust'),
                            meta: {title: '我的上传'}
                        },
                        {
                            path: 'apply',
                            component: () => import(/* webpackChunkName: "dashboard" */ '../components/web/Apply'),
                            meta: {title: '我的申请'}
                       },
                    ]
                },
                ]
        },
        {
            path: '/login',
            component: () => import(/* webpackChunkName: "login" */ '../components/page/Login.vue'),
            meta: { title: '登录' }
        },
        {
            path: '/register',
            component: () => import(/* webpackChunkName: "login" */ '../components/page/Register'),
            meta: { title: '注册' }
        },
        //如果这里后面路由有问题，把这个404注释掉
        {
            path: '*',
            redirect: '/404'
        }
    ]
});

router.beforeEach((to,from,next) =>{
    if (to.path === '/index' || to.path === '/login' || to.path === '/register') {
        next()
    }else{
        const token = sessionStorage.getItem('userStatus');
        if (!token){
            next('/index')
        }else{
            next();
        }
    }
});


export default router
